if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_modifybillsurbalamt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_modifybillsurbalamt]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


Create  procedure p_modifybillsurbalamt (
  @ackind int,
  @btype int,
  @bid int,
  @amount decimal(18,2),
  @dcamount decimal(18,2)
)  as

declare @sql nvarchar(500),
        @tab varchar(64)
begin
  set nocount on
  if (@btype is null or @bid is null) return

   select @tab=btable from ts_billset where bid=@btype 
  set @sql = N'update ' + @tab + N' set relationsuramt=relationsuramt+@ackind*@amount,dcrelationsuramt=dcrelationsuramt+@ackind*@dcamount,' +
             N'relationcount=relationcount+@ackind where bid=@bid' 
 
  exec sp_executesql @sql,N'@ackind int, @bid int, @amount decimal(18,2), @dcamount decimal(18,2)',
                     @ackind, @bid, @amount, @dcamount
end



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

